package com.anima;

import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

public class MAnim extends Animation {
	
	private double degree = 0;	//	弧度
	
	private final static int ll = 10;	//	半径
	private int nowX;
	private int nowY;
	
	private int centerX = 100;
	private int centerY = 300;
	
	public MAnim() {
		super();
		// TODO Auto-generated constructor stub
	}
	public MAnim(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		// TODO Auto-generated method stub
		//	要想不出现重影 必须 调用父类的方法
		super.applyTransformation(interpolatedTime, t);
		
		Matrix m = t.getMatrix();
		nowX = (int)(Math.cos( degree * (Math.PI / 180)) *  ll ) + centerX;
		nowY = (int)(Math.sin( degree * (Math.PI / 180)) *  ll ) + centerY;
		
		m.preTranslate( -nowX, -nowY );
		m.postTranslate( centerX, centerY );
		
		degree = degree + 15;
		
	}
	@Override
	public void initialize(int width, int height, int parentWidth,
			int parentHeight) {
		// TODO Auto-generated method stub
		//	要想不出现重影 必须 调用父类的方法
		super.initialize(width, height, parentWidth, parentHeight);
		setDuration( 100 );
		setFillAfter( true );
		
		setInterpolator( new LinearInterpolator());

		//	怎么设置一直运动呢  
		//	第一就是 设置重复的次数为无限(INFINITE为无限)
		//	第二就是 repeatMode设置为restart
		this.setRepeatCount(INFINITE);
		this.setRepeatMode(Animation.RESTART);
		

	}
	

	

}
